package com.gurid.service.statistics.task;

import com.gurid.service.statistics.service.DailyService;
import lombok.extern.slf4j.Slf4j;
import org.joda.time.DateTime;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

@Component
@Slf4j
//任务调度
public class ScheduledTask {

    @Autowired
    private DailyService dailyService;

//    private static final String executeByDay = CronGenerator.generateByDay(1);

    //@Scheduled(cron = "0 0 0 1/1 * ?")
    public void task(){
        System.out.println("task1执行");
    }

    @Scheduled(cron = "0 1 1 * * ? ")
    public void task2(){
        log.info("task2执行了……");
        String day = new DateTime().minusDays(1).toString("yyyy-MM-dd");
        dailyService.createStatisticsByDay(day);
    }
}
